﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace LongNet.Util
{
    /// <summary>
    /// Some useful constants.
    /// </summary>
    public static class Constants
    {
        #region LongNet

        /// <summary>
        /// The version of LongNet assembly.
        /// </summary>
        public static readonly Assembly LongNetAssembly;

        /// <summary>
        /// The version of LongNet assembly.
        /// </summary>
        public static readonly string LongNetVersion;

        /// <summary>
        /// The main version of LongNet.
        /// </summary>
        public static readonly string LongNetMainVersion = "1.5";

        internal static readonly ManifestResourceHelper ResourceHelper = null;

        #endregion

        #region Static Constructor

        /// <summary>
        /// Initializes the constants.
        /// </summary>
        static Constants()
        {
            if (IntPtr.Size == 8)
            {
                // 64 bit machine
            }
            else if (IntPtr.Size == 4)
            {
                // 32 bit machine
            }

            LongNetAssembly = Assembly.GetExecutingAssembly();
            LongNetVersion = LongNetAssembly.GetName().Version.ToString();
            ResourceHelper = new ManifestResourceHelper(LongNetAssembly);

            #region ContentTypes

            string contentTypes = @".001=application/x-001
.301=application/x-301
.323=text/h323
.906=application/x-906
.907=drawing/907
.a11=application/x-a11
.acp=audio/x-mei-aac
.ai=application/postscript
.aif=audio/aiff
.aifc=audio/aiff
.aiff=audio/aiff
.anv=application/x-anv
.asa=text/asa
.asf=video/x-ms-asf
.asp=text/asp
.asx=video/x-ms-asf
.au=audio/basic
.avi=video/avi
.awf=application/vnd.adobe.workflow
.biz=text/xml
.bmp=application/x-bmp
.bot=application/x-bot
.c4t=application/x-c4t
.c90=application/x-c90
.cal=application/x-cals
.cat=application/vnd.ms-pki.seccat
.cdf=application/x-netcdf
.cdr=application/x-cdr
.cel=application/x-cel
.cer=application/x-x509-ca-cert
.cg4=application/x-g4
.cgm=application/x-cgm
.cit=application/x-cit
.class=java/*
.cml=text/xml
.cmp=application/x-cmp
.cmx=application/x-cmx
.cot=application/x-cot
.crl=application/pkix-crl
.crt=application/x-x509-ca-cert
.csi=application/x-csi
.css=text/css
.cut=application/x-cut
.dbf=application/x-dbf
.dbm=application/x-dbm
.dbx=application/x-dbx
.dcd=text/xml
.dcx=application/x-dcx
.der=application/x-x509-ca-cert
.dgn=application/x-dgn
.dib=application/x-dib
.dll=application/x-msdownload
.doc=application/msword
.dot=application/msword
.drw=application/x-drw
.dtd=text/xml
.dwf=Model/vnd.dwf
.dwf=application/x-dwf
.dwg=application/x-dwg
.dxb=application/x-dxb
.dxf=application/x-dxf
.edn=application/vnd.adobe.edn
.emf=application/x-emf
.eml=message/rfc822
.ent=text/xml
.epi=application/x-epi
.eps=application/x-ps
.eps=application/postscript
.etd=application/x-ebx
.exe=application/x-msdownload
.fax=image/fax
.fdf=application/vnd.fdf
.fif=application/fractals
.fo=text/xml
.frm=application/x-frm
.g4=application/x-g4
.gbr=application/x-gbr
.gcd=application/x-gcd
.gif=image/gif
.gl2=application/x-gl2
.gp4=application/x-gp4
.hgl=application/x-hgl
.hmr=application/x-hmr
.hpg=application/x-hpgl
.hpl=application/x-hpl
.hqx=application/mac-binhex40
.hrf=application/x-hrf
.hta=application/hta
.htc=text/x-component
.htm=text/html
.html=text/html
.htt=text/webviewhtml
.htx=text/html
.icb=application/x-icb
.ico=image/x-icon
.ico=application/x-ico
.iff=application/x-iff
.ig4=application/x-g4
.igs=application/x-igs
.iii=application/x-iphone
.img=application/x-img
.ins=application/x-internet-signup
.isp=application/x-internet-signup
.IVF=video/x-ivf
.java=java/*
.jfif=image/jpeg
.jpe=image/jpeg
.jpe=application/x-jpe
.jpeg=image/jpeg
.jpg=image/jpeg
.jpg=application/x-jpg
.js=application/x-javascript
.jsp=text/html
.la1=audio/x-liquid-file
.lar=application/x-laplayer-reg
.latex=application/x-latex
.lavs=audio/x-liquid-secure
.lbm=application/x-lbm
.lmsff=audio/x-la-lms
.ls=application/x-javascript
.ltr=application/x-ltr
.m1v=video/x-mpeg
.m2v=video/x-mpeg
.m3u=audio/mpegurl
.m4e=video/mpeg4
.mac=application/x-mac
.man=application/x-troff-man
.math=text/xml
.mdb=application/msaccess
.mdb=application/x-mdb
.mfp=application/x-shockwave-flash
.mht=message/rfc822
.mhtml=message/rfc822
.mi=application/x-mi
.mid=audio/mid
.midi=audio/mid
.mil=application/x-mil
.mml=text/xml
.mnd=audio/x-musicnet-download
.mns=audio/x-musicnet-stream
.mocha=application/x-javascript
.movie=video/x-sgi-movie
.mp1=audio/mp1
.mp2=audio/mp2
.mp2v=video/mpeg
.mp3=audio/mp3
.mp4=video/mpeg4
.mpa=video/x-mpg
.mpd=application/vnd.ms-project
.mpe=video/x-mpeg
.mpeg=video/mpg
.mpg=video/mpg
.mpga=audio/rn-mpeg
.mpp=application/vnd.ms-project
.mps=video/x-mpeg
.mpt=application/vnd.ms-project
.mpv=video/mpg
.mpv2=video/mpeg
.mpw=application/vnd.ms-project
.mpx=application/vnd.ms-project
.mtx=text/xml
.mxp=application/x-mmxp
.net=image/pnetvue
.nrf=application/x-nrf
.nws=message/rfc822
.odc=text/x-ms-odc
.out=application/x-out
.p10=application/pkcs10
.p12=application/x-pkcs12
.p7b=application/x-pkcs7-certificates
.p7c=application/pkcs7-mime
.p7m=application/pkcs7-mime
.p7r=application/x-pkcs7-certreqresp
.p7s=application/pkcs7-signature
.pc5=application/x-pc5
.pci=application/x-pci
.pcl=application/x-pcl
.pcx=application/x-pcx
.pdf=application/pdf
.pdf=application/pdf
.pdx=application/vnd.adobe.pdx
.pfx=application/x-pkcs12
.pgl=application/x-pgl
.pic=application/x-pic
.pko=application/vnd.ms-pki.pko
.pl=application/x-perl
.plg=text/html
.pls=audio/scpls
.plt=application/x-plt
.png=image/png
.png=application/x-png
.pot=application/vnd.ms-powerpoint
.ppa=application/vnd.ms-powerpoint
.ppm=application/x-ppm
.pps=application/vnd.ms-powerpoint
.ppt=application/vnd.ms-powerpoint
.ppt=application/x-ppt
.pr=application/x-pr
.prf=application/pics-rules
.prn=application/x-prn
.prt=application/x-prt
.ps=application/x-ps
.ps=application/postscript
.ptn=application/x-ptn
.pwz=application/vnd.ms-powerpoint
.r3t=text/vnd.rn-realtext3d
.ra=audio/vnd.rn-realaudio
.ram=audio/x-pn-realaudio
.ras=application/x-ras
.rat=application/rat-file
.rdf=text/xml
.rec=application/vnd.rn-recording
.red=application/x-red
.rgb=application/x-rgb
.rjs=application/vnd.rn-realsystem-rjs
.rjt=application/vnd.rn-realsystem-rjt
.rlc=application/x-rlc
.rle=application/x-rle
.rm=application/vnd.rn-realmedia
.rmf=application/vnd.adobe.rmf
.rmi=audio/mid
.rmj=application/vnd.rn-realsystem-rmj
.rmm=audio/x-pn-realaudio
.rmp=application/vnd.rn-rn_music_package
.rms=application/vnd.rn-realmedia-secure
.rmvb=application/vnd.rn-realmedia-vbr
.rmx=application/vnd.rn-realsystem-rmx
.rnx=application/vnd.rn-realplayer
.rp=image/vnd.rn-realpix
.rpm=audio/x-pn-realaudio-plugin
.rsml=application/vnd.rn-rsml
.rt=text/vnd.rn-realtext
.rtf=application/msword
.rtf=application/x-rtf
.rv=video/vnd.rn-realvideo
.sam=application/x-sam
.sat=application/x-sat
.sdp=application/sdp
.sdw=application/x-sdw
.sit=application/x-stuffit
.slb=application/x-slb
.sld=application/x-sld
.slk=drawing/x-slk
.smi=application/smil
.smil=application/smil
.smk=application/x-smk
.snd=audio/basic
.sol=text/plain
.sor=text/plain
.spc=application/x-pkcs7-certificates
.spl=application/futuresplash
.spp=text/xml
.ssm=application/streamingmedia
.sst=application/vnd.ms-pki.certstore
.stl=application/vnd.ms-pki.stl
.stm=text/html
.sty=application/x-sty
.svg=text/xml
.swf=application/x-shockwave-flash
.tdf=application/x-tdf
.tg4=application/x-tg4
.tga=application/x-tga
.tif=image/tiff
.tif=application/x-tif
.tiff=image/tiff
.tld=text/xml
.top=drawing/x-top
.torrent=application/x-bittorrent
.tsd=text/xml
.txt=text/plain
.uin=application/x-icq
.uls=text/iuls
.vcf=text/x-vcard
.vda=application/x-vda
.vdx=application/vnd.visio
.vml=text/xml
.vpg=application/x-vpeg005
.vsd=application/vnd.visio
.vsd=application/x-vsd
.vss=application/vnd.visio
.vst=application/vnd.visio
.vst=application/x-vst
.vsw=application/vnd.visio
.vsx=application/vnd.visio
.vtx=application/vnd.visio
.vxml=text/xml
.wav=audio/wav
.wax=audio/x-ms-wax
.wb1=application/x-wb1
.wb2=application/x-wb2
.wb3=application/x-wb3
.wbmp=image/vnd.wap.wbmp
.wiz=application/msword
.wk3=application/x-wk3
.wk4=application/x-wk4
.wkq=application/x-wkq
.wks=application/x-wks
.wm=video/x-ms-wm
.wma=audio/x-ms-wma
.wmd=application/x-ms-wmd
.wmf=application/x-wmf
.wml=text/vnd.wap.wml
.wmv=video/x-ms-wmv
.wmx=video/x-ms-wmx
.wmz=application/x-ms-wmz
.wp6=application/x-wp6
.wpd=application/x-wpd
.wpg=application/x-wpg
.wpl=application/vnd.ms-wpl
.wq1=application/x-wq1
.wr1=application/x-wr1
.wri=application/x-wri
.wrk=application/x-wrk
.ws=application/x-ws
.ws2=application/x-ws
.wsc=text/scriptlet
.wsdl=text/xml
.wvx=video/x-ms-wvx
.xdp=application/vnd.adobe.xdp
.xdr=text/xml
.xfd=application/vnd.adobe.xfd
.xfdf=application/vnd.adobe.xfdf
.xhtml=text/html
.xls=application/vnd.ms-excel
.xls=application/x-xls
.xlw=application/x-xlw
.xml=text/xml
.xpl=audio/scpls
.xq=text/xml
.xql=text/xml
.xquery=text/xml
.xsd=text/xml
.xsl=text/xml
.xslt=text/xml
.xwd=application/x-xwd
.x_b=application/x-x_b
.x_t=application/x-x_t
.*=application/octet-stream";

            FileContentTypes = new Dictionary<string, string>();
            foreach (var s in Utils.SplitString(contentTypes, Utils.NewLine, true))
            {
                string[] arr = s.Split('=');
                if (FileContentTypes.ContainsKey(arr[0]) == false)
                    FileContentTypes.Add(arr[0], arr[1]);
            }

            #endregion

            #region HexStringTable

            //HexStringTable = new string[256];
            //for (int i = 0; i < 256; ++i)
            //{
            //    HexStringTable[i] = string.Concat(HexAlphabet[(int)(i >> 4)], HexAlphabet[(int)(i & 0xF)]);
            //}
            for (int i = 0; i < HexStringTable.Length; i++)
            {
                HexStringIndexTable[HexStringTable[i]] = (byte)i;
            }

            #endregion
        }

        #endregion

        #region Internal Constants

        internal static readonly Dictionary<string, string> FileContentTypes;

        internal static readonly DateTime GmtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
        internal static readonly DateTime GmtDateTimeCn = new DateTime(1970, 1, 1, 8, 0, 0, 0);



        #region HexStringTable

        internal const string HexAlphabet = "0123456789ABCDEF";
        internal static readonly string[] HexStringTable = new string[]
        {
            "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0A", "0B", "0C", "0D", "0E", "0F",
            "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1A", "1B", "1C", "1D", "1E", "1F",
            "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2A", "2B", "2C", "2D", "2E", "2F",
            "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3A", "3B", "3C", "3D", "3E", "3F",
            "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4A", "4B", "4C", "4D", "4E", "4F",
            "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5A", "5B", "5C", "5D", "5E", "5F",
            "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6A", "6B", "6C", "6D", "6E", "6F",
            "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7A", "7B", "7C", "7D", "7E", "7F",
            "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8A", "8B", "8C", "8D", "8E", "8F",
            "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9A", "9B", "9C", "9D", "9E", "9F",
            "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "AA", "AB", "AC", "AD", "AE", "AF",
            "B0", "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "BA", "BB", "BC", "BD", "BE", "BF",
            "C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "CA", "CB", "CC", "CD", "CE", "CF",
            "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "DA", "DB", "DC", "DD", "DE", "DF",
            "E0", "E1", "E2", "E3", "E4", "E5", "E6", "E7", "E8", "E9", "EA", "EB", "EC", "ED", "EE", "EF",
            "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "FA", "FB", "FC", "FD", "FE", "FF"
        };
        internal static readonly Dictionary<string, byte> HexStringIndexTable = new Dictionary<string, byte>(StringComparer.OrdinalIgnoreCase);


        #endregion

        #region Pinyin Name/Value

        internal static int[] PinyinAsciiValue = new int[]
        {
            -20319,-20317,-20304,-20295,-20292,-20283,-20265,-20257,-20242,-20230,-20051,-20036,
            -20032,-20026,-20002,-19990,-19986,-19982,-19976,-19805,-19784,-19775,-19774,-19763,
            -19756,-19751,-19746,-19741,-19739,-19728,-19725,-19715,-19540,-19531,-19525,-19515,
            -19500,-19484,-19479,-19467,-19289,-19288,-19281,-19275,-19270,-19263,-19261,-19249,
            -19243,-19242,-19238,-19235,-19227,-19224,-19218,-19212,-19038,-19023,-19018,-19006,
            -19003,-18996,-18977,-18961,-18952,-18783,-18774,-18773,-18763,-18756,-18741,-18735,
            -18731,-18722,-18710,-18697,-18696,-18526,-18518,-18501,-18490,-18478,-18463,-18448,
            -18447,-18446,-18239,-18237,-18231,-18220,-18211,-18201,-18184,-18183, -18181,-18012,
            -17997,-17988,-17970,-17964,-17961,-17950,-17947,-17931,-17928,-17922,-17759,-17752,
            -17733,-17730,-17721,-17703,-17701,-17697,-17692,-17683,-17676,-17496,-17487,-17482,
            -17468,-17454,-17433,-17427,-17417,-17202,-17185,-16983,-16970,-16942,-16915,-16733,
            -16708,-16706,-16689,-16664,-16657,-16647,-16474,-16470,-16465,-16459,-16452,-16448,
            -16433,-16429,-16427,-16423,-16419,-16412,-16407,-16403,-16401,-16393,-16220,-16216,
            -16212,-16205,-16202,-16187,-16180,-16171,-16169,-16158,-16155,-15959,-15958,-15944,
            -15933,-15920,-15915,-15903,-15889,-15878,-15707,-15701,-15681,-15667,-15661,-15659,
            -15652,-15640,-15631,-15625,-15454,-15448,-15436,-15435,-15419,-15416,-15408,-15394,
            -15385,-15377,-15375,-15369,-15363,-15362,-15183,-15180,-15165,-15158,-15153,-15150,
            -15149,-15144,-15143,-15141,-15140,-15139,-15128,-15121,-15119,-15117,-15110,-15109,
            -14941,-14937,-14933,-14930,-14929,-14928,-14926,-14922,-14921,-14914,-14908,-14902,
            -14894,-14889,-14882,-14873,-14871,-14857,-14678,-14674,-14670,-14668,-14663,-14654,
            -14645,-14630,-14594,-14429,-14407,-14399,-14384,-14379,-14368,-14355,-14353,-14345,
            -14170,-14159,-14151,-14149,-14145,-14140,-14137,-14135,-14125,-14123,-14122,-14112,
            -14109,-14099,-14097,-14094,-14092,-14090,-14087,-14083,-13917,-13914,-13910,-13907,
            -13906,-13905,-13896,-13894,-13878,-13870,-13859,-13847,-13831,-13658,-13611,-13601,
            -13406,-13404,-13400,-13398,-13395,-13391,-13387,-13383,-13367,-13359,-13356,-13343,
            -13340,-13329,-13326,-13318,-13147,-13138,-13120,-13107,-13096,-13095,-13091,-13076,
            -13068,-13063,-13060,-12888,-12875,-12871,-12860,-12858,-12852,-12849,-12838,-12831,
            -12829,-12812,-12802,-12607,-12597,-12594,-12585,-12556,-12359,-12346,-12320,-12300,
            -12120,-12099,-12089,-12074,-12067,-12058,-12039,-11867,-11861,-11847,-11831,-11798,
            -11781,-11604,-11589,-11536,-11358,-11340,-11339,-11324,-11303,-11097,-11077,-11067,
            -11055,-11052,-11045,-11041,-11038,-11024,-11020,-11019,-11018,-11014,-10838,-10832,
            -10815,-10800,-10790,-10780,-10764,-10587,-10544,-10533,-10519,-10331,-10329,-10328,
            -10322,-10315,-10309,-10307,-10296,-10281,-10274,-10270,-10262,-10260,-10256,-10254
        };

        internal static string[] PinyinSpellValue = new string[]
        {
            "A","Ai","An","Ang","Ao","Ba","Bai","Ban","Bang","Bao","Bei","Ben",
            "Beng","Bi","Bian","Biao","Bie","Bin","Bing","Bo","Bu","Ba","Cai","Can",
            "Cang","Cao","Ce","Ceng","Cha","Chai","Chan","Chang","Chao","Che","Chen","Cheng",
            "Chi","Chong","Chou","Chu","Chuai","Chuan","Chuang","Chui","Chun","Chuo","Ci","Cong",
            "Cou","Cu","Cuan","Cui","Cun","Cuo","Da","Dai","Dan","Dang","Dao","De",
            "Deng","Di","Dian","Diao","Die","Ding","Diu","Dong","Dou","Du","Duan","Dui",
            "Dun","Duo","E","En","Er","Fa","Fan","Fang","Fei","Fen","Feng","Fo",
            "Fou","Fu","Ga","Gai","Gan","Gang","Gao","Ge","Gei","Gen","Geng","Gong",
            "Gou","Gu","Gua","Guai","Guan","Guang","Gui","Gun","Guo","Ha","Hai","Han",
            "Hang","Hao","He","Hei","Hen","Heng","Hong","Hou","Hu","Hua","Huai","Huan",
            "Huang","Hui","Hun","Huo","Ji","Jia","Jian","Jiang","Jiao","Jie","Jin","Jing",
            "Jiong","Jiu","Ju","Juan","Jue","Jun","Ka","Kai","Kan","Kang","Kao","Ke",
            "Ken","Keng","Kong","Kou","Ku","Kua","Kuai","Kuan","Kuang","Kui","Kun","Kuo",
            "La","Lai","Lan","Lang","Lao","Le","Lei","Leng","Li","Lia","Lian","Liang",
            "Liao","Lie","Lin","Ling","Liu","Long","Lou","Lu","Lv","Luan","Lue","Lun",
            "Luo","Ma","Mai","Man","Mang","Mao","Me","Mei","Men","Meng","Mi","Mian",
            "Miao","Mie","Min","Ming","Miu","Mo","Mou","Mu","Na","Nai","Nan","Nang",
            "Nao","Ne","Nei","Nen","Neng","Ni","Nian","Niang","Niao","Nie","Nin","Ning",
            "Niu","Nong","Nu","Nv","Nuan","Nue","Nuo","O","Ou","Pa","Pai","Pan",
            "Pang","Pao","Pei","Pen","Peng","Pi","Pian","Piao","Pie","Pin","Ping","Po",
            "Pu","Qi","Qia","Qian","Qiang","Qiao","Qie","Qin","Qing","Qiong","Qiu","Qu",
            "Quan","Que","Qun","Ran","Rang","Rao","Re","Ren","Reng","Ri","Rong","Rou",
            "Ru","Ruan","Rui","Run","Ruo","Sa","Sai","San","Sang","Sao","Se","Sen",
            "Seng","Sha","Shai","Shan","Shang","Shao","She","Shen","Sheng","Shi","Shou","Shu",
            "Shua","Shuai","Shuan","Shuang","Shui","Shun","Shuo","Si","Song","Sou","Su","Suan",
            "Sui","Sun","Suo","Ta","Tai","Tan","Tang","Tao","Te","Teng","Ti","Tian",
            "Tiao","Tie","Ting","Tong","Tou","Tu","Tuan","Tui","Tun","Tuo","Wa","Wai",
            "Wan","Wang","Wei","Wen","Weng","Wo","Wu","Xi","Xia","Xian","Xiang","Xiao",
            "Xie","Xin","Xing","Xiong","Xiu","Xu","Xuan","Xue","Xun","Ya","Yan","Yang",
            "Yao","Ye","Yi","Yin","Ying","Yo","Yong","You","Yu","Yuan","Yue","Yun",
            "Za", "Zai","Zan","Zang","Zao","Ze","Zei","Zen","Zeng","Zha","Zhai","Zhan",
            "Zhang","Zhao","Zhe","Zhen","Zheng","Zhi","Zhong","Zhou","Zhu","Zhua","Zhuai","Zhuan",
            "Zhuang","Zhui","Zhun","Zhuo","Zi","Zong","Zou","Zu","Zuan","Zui","Zun","Zuo"
        };

        #endregion

        #endregion
    }
}
